package bullsora.kindlerss.controllers;

import com.bullsora.kindlerss.business.InitUsersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
import javax.servlet.http.HttpServletResponse;

/**
 * @author sorin.buliarca@iquesint.com
 */
@Controller
public class InitUsersController {

  private InitUsersService initUsersService;

  private Properties initUserProperties;

  @RequestMapping(value = "/initUsers")
  public void initUsers() {
    initUsersService.initUsers(initUserProperties);
  }

  @RequestMapping(value = "/init", method = RequestMethod.POST)
  public void initFromProps(InputStream bodyContents) throws IOException {
    Properties userProps = new Properties();
    userProps.load(bodyContents);
    initUsersService.initUsers(userProps);
  }

  public InitUsersService getInitUsersService() {
    return initUsersService;
  }

  public void setInitUsersService(InitUsersService initUsersService) {
    this.initUsersService = initUsersService;
  }

  public Properties getInitUserProperties() {
    return initUserProperties;
  }

  public void setInitUserProperties(Properties initUserProperties) {
    this.initUserProperties = initUserProperties;
  }
}
